﻿using EmitDebugging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Spackle.Testing;
using System;
using System.Reflection.Emit;

namespace EmitDebugging.Tests
{
	[TestClass]
	public sealed class CodeLineTests : CoreTests
	{
		[TestMethod]
		public void CreateCodeLineViaCode()
		{
			CodeLine line = new CodeLine("code");
			Assert.AreEqual("code", line.Code);
			Assert.AreEqual(Indention.KeepCurrent, line.Indent);
			Assert.IsFalse(line.IsDebuggable);
			Assert.AreEqual(0, line.Labels.Length);
		}

		[TestMethod]
		public void CreateCodeLineViaCodeAndIndention()
		{
			CodeLine line = new CodeLine("code", Indention.Increase);
			Assert.AreEqual("code", line.Code);
			Assert.AreEqual(Indention.Increase, line.Indent);
			Assert.IsFalse(line.IsDebuggable);
			Assert.AreEqual(0, line.Labels.Length);
		}

		[TestMethod]
		public void CreateCodeLineViaCodeAndIsDebuggable()
		{
			CodeLine line = new CodeLine("code", true);
			Assert.AreEqual("code", line.Code);
			Assert.AreEqual(Indention.KeepCurrent, line.Indent);
			Assert.IsTrue(line.IsDebuggable);
			Assert.AreEqual(0, line.Labels.Length);
		}

		[TestMethod]
		public void CreateCodeLineViaCodeAndIndentionAndIsDebuggable()
		{
			CodeLine line = new CodeLine("code", Indention.Decrease, true);
			Assert.AreEqual("code", line.Code);
			Assert.AreEqual(Indention.Decrease, line.Indent);
			Assert.IsTrue(line.IsDebuggable);
			Assert.AreEqual(0, line.Labels.Length);
		}

		[TestMethod]
		public void CreateCodeLineViaCodeAndIndentionAndLabels()
		{
			CodeLine line = new CodeLine("code", Indention.Increase, new Label());
			Assert.AreEqual("code", line.Code);
			Assert.AreEqual(Indention.Increase, line.Indent);
			Assert.IsFalse(line.IsDebuggable);
			Assert.AreEqual(1, line.Labels.Length);
		}

		[TestMethod]
		public void CreateCodeLineViaCodeAndSetCode()
		{
			CodeLine line = new CodeLine("code");
			line.Code = "new code";
			Assert.AreEqual("new code", line.Code);
		}

		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void CreateCodeLineViaCodeAndSetCodeNull()
		{
			CodeLine line = new CodeLine("code");
			line.Code = null;
		}

		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void CreateCodeLineViaCodeAsNull()
		{
			new CodeLine(null);
		}
	}
}
